#include <stdio.h>
#include <string.h>

#include "cJSON.h"



int parser_json(char *buf,char *id,int idsize,float *temp,char *timep)
{
        cJSON                   *root;
        cJSON                   *item;


//      printf("start parser_json!\n");
        if(!buf||!id||!temp)
        {
                printf("Invaild input arguments\n");
                return -1;
        }

        root = cJSON_Parse(buf);

        if(!root)
        {
                printf("cJson_Parse buf failure!\n");
                return -2;
        }


        item = cJSON_GetObjectItem(root,"id");
        strncpy(id,item->valuestring,8);

        item = cJSON_GetObjectItem(root,"time");
        strcpy(timep,item->valuestring);

        item = cJSON_GetObjectItem(root,"temperature");
        *temp = item->valuedouble;

        cJSON_Delete(root);

}

